package com.zack.xjht.db.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zack.xjht.entity.OfflineTaskItem;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "OFFLINE_TASK_ITEM".
*/
public class OfflineTaskItemDao extends AbstractDao<OfflineTaskItem, Long> {

    public static final String TABLENAME = "OFFLINE_TASK_ITEM";

    /**
     * Properties of entity OfflineTaskItem.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "_id");
        public final static Property LocationId = new Property(1, String.class, "locationId", false, "LOCATION_ID");
        public final static Property ObjectId = new Property(2, String.class, "objectId", false, "OBJECT_ID");
        public final static Property LocationType = new Property(3, String.class, "locationType", false, "LOCATION_TYPE");
        public final static Property ObjectType = new Property(4, String.class, "objectType", false, "OBJECT_TYPE");
        public final static Property ObjectNum = new Property(5, int.class, "objectNum", false, "OBJECT_NUM");
        public final static Property BackNum = new Property(6, int.class, "backNum", false, "BACK_NUM");
        public final static Property GunNo = new Property(7, String.class, "gunNo", false, "GUN_NO");
        public final static Property Status = new Property(8, int.class, "status", false, "STATUS");
        public final static Property LocationNo = new Property(9, int.class, "locationNo", false, "LOCATION_NO");
        public final static Property TaskId = new Property(10, long.class, "taskId", false, "TASK_ID");
        public final static Property SubCabId = new Property(11, long.class, "subCabId", false, "SUB_CAB_ID");
        public final static Property UserId = new Property(12, String.class, "userId", false, "USER_ID");
        public final static Property UserName = new Property(13, String.class, "userName", false, "USER_NAME");
    }

    private Query<OfflineTaskItem> offlineTask_OfflineTaskItemListQuery;

    public OfflineTaskItemDao(DaoConfig config) {
        super(config);
    }
    
    public OfflineTaskItemDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"OFFLINE_TASK_ITEM\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"LOCATION_ID\" TEXT," + // 1: locationId
                "\"OBJECT_ID\" TEXT," + // 2: objectId
                "\"LOCATION_TYPE\" TEXT," + // 3: locationType
                "\"OBJECT_TYPE\" TEXT," + // 4: objectType
                "\"OBJECT_NUM\" INTEGER NOT NULL ," + // 5: objectNum
                "\"BACK_NUM\" INTEGER NOT NULL ," + // 6: backNum
                "\"GUN_NO\" TEXT," + // 7: gunNo
                "\"STATUS\" INTEGER NOT NULL ," + // 8: status
                "\"LOCATION_NO\" INTEGER NOT NULL ," + // 9: locationNo
                "\"TASK_ID\" INTEGER NOT NULL ," + // 10: taskId
                "\"SUB_CAB_ID\" INTEGER NOT NULL ," + // 11: subCabId
                "\"USER_ID\" TEXT," + // 12: userId
                "\"USER_NAME\" TEXT);"); // 13: userName
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"OFFLINE_TASK_ITEM\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, OfflineTaskItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String locationId = entity.getLocationId();
        if (locationId != null) {
            stmt.bindString(2, locationId);
        }
 
        String objectId = entity.getObjectId();
        if (objectId != null) {
            stmt.bindString(3, objectId);
        }
 
        String locationType = entity.getLocationType();
        if (locationType != null) {
            stmt.bindString(4, locationType);
        }
 
        String objectType = entity.getObjectType();
        if (objectType != null) {
            stmt.bindString(5, objectType);
        }
        stmt.bindLong(6, entity.getObjectNum());
        stmt.bindLong(7, entity.getBackNum());
 
        String gunNo = entity.getGunNo();
        if (gunNo != null) {
            stmt.bindString(8, gunNo);
        }
        stmt.bindLong(9, entity.getStatus());
        stmt.bindLong(10, entity.getLocationNo());
        stmt.bindLong(11, entity.getTaskId());
        stmt.bindLong(12, entity.getSubCabId());
 
        String userId = entity.getUserId();
        if (userId != null) {
            stmt.bindString(13, userId);
        }
 
        String userName = entity.getUserName();
        if (userName != null) {
            stmt.bindString(14, userName);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, OfflineTaskItem entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String locationId = entity.getLocationId();
        if (locationId != null) {
            stmt.bindString(2, locationId);
        }
 
        String objectId = entity.getObjectId();
        if (objectId != null) {
            stmt.bindString(3, objectId);
        }
 
        String locationType = entity.getLocationType();
        if (locationType != null) {
            stmt.bindString(4, locationType);
        }
 
        String objectType = entity.getObjectType();
        if (objectType != null) {
            stmt.bindString(5, objectType);
        }
        stmt.bindLong(6, entity.getObjectNum());
        stmt.bindLong(7, entity.getBackNum());
 
        String gunNo = entity.getGunNo();
        if (gunNo != null) {
            stmt.bindString(8, gunNo);
        }
        stmt.bindLong(9, entity.getStatus());
        stmt.bindLong(10, entity.getLocationNo());
        stmt.bindLong(11, entity.getTaskId());
        stmt.bindLong(12, entity.getSubCabId());
 
        String userId = entity.getUserId();
        if (userId != null) {
            stmt.bindString(13, userId);
        }
 
        String userName = entity.getUserName();
        if (userName != null) {
            stmt.bindString(14, userName);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public OfflineTaskItem readEntity(Cursor cursor, int offset) {
        OfflineTaskItem entity = new OfflineTaskItem( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // locationId
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // objectId
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // locationType
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // objectType
            cursor.getInt(offset + 5), // objectNum
            cursor.getInt(offset + 6), // backNum
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // gunNo
            cursor.getInt(offset + 8), // status
            cursor.getInt(offset + 9), // locationNo
            cursor.getLong(offset + 10), // taskId
            cursor.getLong(offset + 11), // subCabId
            cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12), // userId
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13) // userName
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, OfflineTaskItem entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setLocationId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setObjectId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setLocationType(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setObjectType(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setObjectNum(cursor.getInt(offset + 5));
        entity.setBackNum(cursor.getInt(offset + 6));
        entity.setGunNo(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setStatus(cursor.getInt(offset + 8));
        entity.setLocationNo(cursor.getInt(offset + 9));
        entity.setTaskId(cursor.getLong(offset + 10));
        entity.setSubCabId(cursor.getLong(offset + 11));
        entity.setUserId(cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12));
        entity.setUserName(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(OfflineTaskItem entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(OfflineTaskItem entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(OfflineTaskItem entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "offlineTaskItemList" to-many relationship of OfflineTask. */
    public List<OfflineTaskItem> _queryOfflineTask_OfflineTaskItemList(long taskId) {
        synchronized (this) {
            if (offlineTask_OfflineTaskItemListQuery == null) {
                QueryBuilder<OfflineTaskItem> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.TaskId.eq(null));
                offlineTask_OfflineTaskItemListQuery = queryBuilder.build();
            }
        }
        Query<OfflineTaskItem> query = offlineTask_OfflineTaskItemListQuery.forCurrentThread();
        query.setParameter(0, taskId);
        return query.list();
    }

}
